{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-13T03:00:01.371943Z",
     "start_time": "2019-03-13T03:00:01.149069Z"
    }
   },
   "outputs": [],
   "source": [
    "\"\"\" Source:\n",
    "      - https://stackoverflow.com/questions/48122744/how-to-download-all-files-and-folder-hierarchy-from-jupyter-notebook\n",
    "\"\"\"\n",
    "import os\n",
    "import tarfile\n",
    "\n",
    "def recursive_files(dir_name='.', ignore=None):\n",
    "    for dir_name,subdirs,files in os.walk(dir_name):\n",
    "        if ignore and os.path.basename(dir_name) in ignore:\n",
    "            continue\n",
    "\n",
    "        for file_name in files:\n",
    "            if ignore and file_name in ignore:\n",
    "                continue\n",
    "\n",
    "            yield os.path.join(dir_name, file_name)\n",
    "\n",
    "def make_tar_file(dir_name='.', target_file_name='workspace_archive.tar', ignore=None):\n",
    "    tar = tarfile.open(target_file_name, 'w')\n",
    "\n",
    "    for file_name in recursive_files(dir_name, ignore):\n",
    "        tar.add(file_name)\n",
    "\n",
    "    tar.close()\n",
    "\n",
    "\n",
    "dir_name = '.'\n",
    "target_file_name = 'workspace_archive.tar'\n",
    "# List of files/directories to ignore\n",
    "ignore = {'.ipynb_checkpoints', '__pycache__', target_file_name}\n",
    "\n",
    "make_tar_file(dir_name, target_file_name, ignore)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.6"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
